package com.example.feifei.utils;

import android.content.Context;
import android.widget.Toast;


/**
 * 显示吐司的工具类
 */
public class ToastUtil {
	private static String oldMsg;
	protected static Toast toast = null;
	private static long oneTime = 0;
	private static long twoTime = 0;

	public static void showMessage(Context context, String str) {
		showMessage(context, str, Toast.LENGTH_SHORT);
	}

//	public static void showMessage(Context context, int resId) {
//		showMessage(context, context.getString(resId), Toast.LENGTH_SHORT);
//	}
//
//	public static void showMessage(Context context, int resId, int toastShortOrLong) {
//		showMessage(context, context.getString(resId), toastShortOrLong);
//	}
//
//	public static void showMessage(Context context, int resId, int gravity, int toastShortOrLong) {
//		showMessage(context, context.getString(resId), gravity, 0, 0, toastShortOrLong);
//	}
//
//	public static void showMessage(Context context, String s, int gravity, int toastShortOrLong) {
//		showMessage(context, s, gravity, 0, 0, toastShortOrLong);
//	}
//
//	public static void showMessage(Context context, int resId, int gravity, int offX, int offY, int toastShortOrLong) {
//		showMessage(context, context.getString(resId), gravity, offX, offY, toastShortOrLong);
//	}

	public static void showMessage(Context context, String s, int toastShortOrLong) {
		if (s == null || s.equals("")) {
			return;
		}
		if (toast == null) {
			toast = Toast.makeText(context, s, toastShortOrLong);
			toast.show();
			oneTime = System.currentTimeMillis();
		} else {
			twoTime = System.currentTimeMillis();
			if (s.equals(oldMsg)) {
				if (twoTime - oneTime > 2000) {
					toast.show();
				}
			} else {
				oldMsg = s;
				toast.setText(s);
				toast.show();
			}
		}
		oneTime = twoTime;
	}

//	public static void showMessage(Context context, String s, int gravity, int offX, int offY, int toastShortOrLong) {
//		if (s == null || s.equals("")) {
//			return;
//		}
//		if (toast == null) {
//			toast = Toast.makeText(context, s, toastShortOrLong);
//			toast.setGravity(gravity, offX, offY);
//			toast.show();
//			oneTime = System.currentTimeMillis();
//		} else {
//			twoTime = System.currentTimeMillis();
//			if (s.equals(oldMsg)) {
//				if (twoTime - oneTime > 2000) {
//					toast.show();
//				}
//			} else {
//				oldMsg = s;
//				toast.setText(s);
//				toast.show();
//			}
//		}
//		oneTime = twoTime;
//	}
}